package com.example.shopping.shipping.controller;



import com.example.shopping.JsonResult;


import com.example.shopping.shipping.entity.Shipping;
import com.example.shopping.shipping.mapper.ShippingMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@CrossOrigin
@RestController
public class ShippingController {
    @Autowired
    ShippingMapper shippingMapper;
    //查询
    @RequestMapping("/api/shipping/list")
    public JsonResult getshipping(int userid){
        List<Shipping> shippings= shippingMapper.getshipping(userid);
        return  new JsonResult(true,"查询成功",shippings);
    }
    @RequestMapping("/api/dele/shipping")
    public  JsonResult delshipping(int id){
        int delshipping= shippingMapper.delshipping(id);
        return  new JsonResult(true,"删除成功",delshipping);

    }
    @RequestMapping("/api/addshipping/add")
    public JsonResult addshipping( Shipping shipping){
        int addmember= shippingMapper.addShipping(shipping);
        System.out.println(shipping);
        if (shipping.getDfault()==1){
            shippingMapper.UpdDfault(shipping.getId());
        }
        return  new JsonResult(true,"增加成功",addmember);
    }
    @RequestMapping("/api/updshipping/Upd")
    public JsonResult upShipping(Shipping shipping){
        int msg = shippingMapper.upShipping(shipping);
        if(shipping.getDfault()==1){
            shippingMapper.UpdDfault(shipping.getId());
        }
        return new JsonResult(true,"修改成功",msg);
    }


}
